import request from '@/utils/request'

// 查询采购退货单列表
export function listReturn(query) {
  return request({
    url: '/purchase/return/list',
    method: 'get',
    params: query
  })
}

// 查询采购退货单详细
export function getReturn(returnId) {
  return request({
    url: '/purchase/return/' + returnId,
    method: 'get'
  })
}

// 新增采购退货单
export function addReturn(data) {
  return request({
    url: '/purchase/return',
    method: 'post',
    data: data
  })
}

// 修改采购退货单
export function updateReturn(data) {
  return request({
    url: '/purchase/return',
    method: 'put',
    data: data
  })
}

// 删除采购退货单
export function delReturn(returnId) {
  return request({
    url: '/purchase/return/' + returnId,
    method: 'delete'
  })
}

// 校验退货单编号是否唯一
export function checkReturnCodeUnique(returnCode, returnId) {
  return request({
    url: '/purchase/return/checkReturnCodeUnique',
    method: 'get',
    params: {
      returnCode: returnCode,
      returnId: returnId
    }
  })
}

// 查询已完成退货单列表（历史记录）
export function listCompletedReturn(query) {
  return request({
    url: '/purchase/return/completedList',
    method: 'get',
    params: query
  })
}

// 根据原入库单ID查询退货单列表
export function listReturnByReceiptId(receiptId) {
  return request({
    url: '/purchase/return/receipt/' + receiptId,
    method: 'get'
  })
}

// 根据供应商ID查询退货单列表
export function listReturnBySupplierId(supplierId) {
  return request({
    url: '/purchase/return/supplier/' + supplierId,
    method: 'get'
  })
}

// 根据仓库ID查询退货单列表
export function listReturnByWarehouseId(warehouseId) {
  return request({
    url: '/purchase/return/warehouse/' + warehouseId,
    method: 'get'
  })
}

// 根据退货类型查询退货单列表
export function listReturnByType(returnType) {
  return request({
    url: '/purchase/return/type/' + returnType,
    method: 'get'
  })
}

// 审核采购退货单
export function approveReturn(returnId) {
  return request({
    url: '/purchase/return/approve/' + returnId,
    method: 'put'
  })
}

// 执行采购退货单
export function executeReturn(returnId) {
  return request({
    url: '/purchase/return/execute/' + returnId,
    method: 'put'
  })
}
export function auditReturn(returnId, status) {
  return request({
    url: '/purchase/return/audit/' + returnId + '/' + status,
    method: 'put'
  })
}